// packageF/others/wisdom/wisdomBindTask/wisdomBindTask.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    show: false,
    infoData: [],
    agreementUrl: "",
    status: false,
    income_name_text: wx.getStorageSync('yz_basic_info').lang.income.income_name ? wx.getStorageSync('yz_basic_info').lang.income.income_name : '收入',
    BalanceName: "",
    name_of_withdrawal: wx.getStorageSync('yz_basic_info').lang.income.name_of_withdrawal ? wx.getStorageSync('yz_basic_info').lang.income.name_of_withdrawal : '提现',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.checkAgreement();
    wx.setNavigationBarTitle({
      title: `${this.data.name_of_withdrawal}到银行卡-智E+`,
    })
  },
  toBindCard() {
    wx.navigateTo({
      url: '/packageF/others/wisdom/addWisdomBank/addWisdomBank?to=wisdomBindTask',
    })
  },
  tobind(e) {
    let key = e.currentTarget.dataset.key;
    if (key == "phone") {
      if (this.data.infoData.is_bind_mobile == "1") return;
      wx.navigateTo({
        url: '/packageF/others/wisdom/wisdomBind/wisdomBind?option=phone',
      })
    } else {
      if (this.data.infoData.is_auth == "1") return;
      wx.navigateTo({
        url: '/packageF/others/wisdom/wisdomBind/wisdomBind?option=auth',
      })
    }
  },
  toUrl() {
    if (this.data.infoData.is_agreement == 0) {
      // window.location.href = this.agreementUrl;
      console.log(this.data.agreementUrl)
      wx.navigateTo({
        url: '/packageI/web-view/h5View?isEplus=true',
      })
    }
  },
  tapWithdrawal(e) {
    let key = e.currentTarget.dataset.key;
    if (!this.data.status) {
      return
    }
    if (key == "balance") {
      wx.navigateTo({
        url: '/packageA/member/balance/balance_withdrawals/balance_withdrawals',
      })
    } else {
      wx.navigateTo({
        url: '/packageA/member/withdrawal/withdrawal',
      })
    }
  },
  getData() {
    let url = app.getNetAddresss("plugin.eplus-pay.frontend.index.index");
    app._getNetWork({
      url: url,
      success: (resdata) => {
        let res = resdata.data;
        if (res.result == 1) {
          this.data.infoData = res.data
          this.setData({
            infoData: this.data.infoData
          })
          if (this.data.infoData.is_auth == "1" && this.data.infoData.is_agreement == "1" && this.data.infoData.is_bind_mobile == "1") {
            this.setData({
              status: true
            })
          } else {
            this.setData({
              status: false
            })
          }
          if (this.data.infoData.is_agreement == 0) {
            this.getAgreementUrl();
          }

        } else {
          app.tips(res.msg)
        }
      },
      fail: function (res) {
        console.log(res);
      }
    });
  },
  getAgreementUrl() {
    let url = app.getNetAddresss("plugin.eplus-pay.frontend.agreement.agreementUrl");
    app._getNetWork({
      url: url,
      success: (resdata) => {
        let res = resdata.data;
        if (res.result == 1) {
          this.setData({
            agreementUrl: res.data.url
          })
        } else {
          app.tips(res.msg)
        }
      },
      fail: function (res) {
        console.log(res);
      }
    });
  },
  checkAgreement() {
    let url = app.getNetAddresss("plugin.eplus-pay.frontend.agreement.confirmAgreement");
    app._getNetWork({
      url: url,
      success: (resdata) => {
        let res = resdata.data;
        if (res.result == 1) {
          this.setData({
            'infoData.is_agreement': 1
          })
        }
      },
      fail: function (res) {
        console.log(res);
      }
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getData();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})